<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/5/5
 * Time: 13:12
 */

namespace app\shopping\controller;

use app\common\model\Base;

class Shoppingbasicsinfo extends Base{

    public function index(){
        $jsonArray = (object) array();
        $address = $this->getAddress();
        $commSystem = $this->getCommSystem();
        $address ? $jsonArray->detailed_address = $address : '';
        $commSystem ? $jsonArray->shoppingBasicsInfo = $commSystem : '';
        echo echoJson(1, $jsonArray);
    }


    /**
     *  得到地址
     * @param str $uid 账号
     */
    function getAddress() {
        $uid = getParameter("uid");
        if (empty($uid) || $uid == "undefined") {
            return false;
        }
        $sql = "SELECT id,name,address,detailed_address ,tel FROM sopp_user_address WHERE  uid='$uid' and default_state=1 and is_show=1 ORDER BY datetime DESC";
        $row = $this->mysql->selectSQLRow($sql);

        if ($row) {
            if (!empty($row['id']) && !empty($row['address']) && !empty($row['detailed_address'])) {
                !empty($row['name']) ? $name = $row['name'] : $name = null;
                !empty($row['tel']) ? $tel = $row['tel'] : $tel = null;
                $jsonArray = array('id' => $row['id'], 'name' => $name, 'address' => $row['address'],
                    'detailed_address' => $row['detailed_address'], 'tel' => $tel);
            } else {
                return false;
            }
            if (count($jsonArray) > 0) {
                return $jsonArray;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * 付款的基本信息
     */
    function getCommSystem() {
        $sql = "SELECT * FROM sopp_basics_info";
        $result = $this->mysql->selectSQLAll($sql);
        $jsonArray = (object) array();
        if (is_array($result)) {
            $expressageArray = array();
            $invoiceArray = array();
            $modeOfPaymentArray = array();
            foreach ($result as $row) {
                !empty($row['expressage']) ? $expressageArray[] = $row['expressage'] : "";
                !empty($row['invoice']) ? $invoiceArray[] = $row['invoice'] : "";
                !empty($row['modeOfPayment']) ? $modeOfPaymentArray[] = $row['modeOfPayment'] : "";
            }
            count($expressageArray) > 0 ? $jsonArray->expressage = $expressageArray : '';
            count($invoiceArray) > 0 ? $jsonArray->invoice = $invoiceArray : '';
            count($modeOfPaymentArray) > 0 ? $jsonArray->modeOfPayment = $modeOfPaymentArray : '';
            if (count($jsonArray) > 0) {
                return $jsonArray;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}